<%--
  Created by IntelliJ IDEA.
  User: 董哥
  Date: 2020/7/17
  Time: 12:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>教练列表</title>
    <script type="text/Javascript" src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no,initial-scale=1.0 maximum-scale=1.0,minimum-scale=1.0">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/normalize.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/jllst.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_1728297_bs63i8tei97.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_1728297_tk74qpi13cs.css">
    <script src="${pageContext.request.contextPath}/js/flexible.js"></script>
    <script src="//cdn.bootcss.com/jquery/2.1.0/jquery.js"></script>
    <script type="text/javascript"
            src="https://api.map.baidu.com/api?v=2.0&ak=hCBcm8H8opRLdC0f6OibbGavC0pne1uc"></script>
    <script type="text/javascript">
        var lon, lat;

        function getLocation() {
            if (navigator.geolocation) {
                alert("您的浏览器支持本系统!\n由于获取用户的定位需要一段时间，大概10秒左右，请在【弹出定位成功的窗口后】进行签到操作.");
                navigator.geolocation.getCurrentPosition(showPosition, showError);
            } else {
                alert("浏览器不支持地理定位。");
            }
        }

        getLocation();

        function showError(error) {
            switch (error.code) {
                case error.PERMISSION_DENIED:
                    alert("定位失败,用户拒绝请求地理定位");
                    break;
                case error.POSITION_UNAVAILABLE:
                    alert("定位失败,位置信息是不可用");
                    break;
                case error.TIMEOUT:
                    alert("定位失败,请求获取用户位置超时");
                    break;
                case error.UNKNOWN_ERROR:
                    alert("定位失败,定位系统失效");
                    break;
            }
        };

        function showPosition(position) {
            var latlon = position.coords.latitude + ',' + position.coords.longitude;
            var url = "https://api.map.baidu.com/geocoder/v2/?ak=hCBcm8H8opRLdC0f6OibbGavC0pne1uc&callback=renderReverse&location=" + latlon + "&output=json&pois=0";
            $.ajax({
                type: "GET",
                dataType: "jsonp",
                url: url,
                success: function (json) {
                    console.log(json);
                    var ggPoint = new BMap.Point(json.result.location.lng, json.result.location.lat); //创建标点
                    //坐标转换完之后的回调函数
                    translateCallback = function (data) {
                        if (data.status === 0) {
                            var marker = new BMap.Marker(data.points[0]);
                            maximumAge:10;
                            lon = data.points[0].lng;
                            lat = data.points[0].lat;
                            alert("定位成功!！【签到记得在右上角的框中写入名字，否则无法录入列表】\n您的经纬度：" + lat + ',' + lon);
                            $(".onee").click(function () {
                                var writeForm = $('.writeForm');
                                writeForm.attr('action', '${pageContext.request.contextPath}/user/saveyy?xian=1&jd=' + lon + '&wd=' + lat);
                                writeForm.submit();
                            });
                            $(".twoo").click(function () {
                                var writeForm = $('.writeForm');
                                writeForm.attr('action', '${pageContext.request.contextPath}/user/saveyy?xian=2&jd=' + lon + '&wd=' + lat);
                                writeForm.submit();
                            });
                            $(".threee").click(function () {
                                var writeForm = $('.writeForm');
                                writeForm.attr('action', '${pageContext.request.contextPath}/user/saveyy?xian=3&jd=' + lon + '&wd=' + lat);
                                writeForm.submit();
                            });
                            $(".fourr").click(function () {
                                var writeForm = $('.writeForm');
                                writeForm.attr('action', '${pageContext.request.contextPath}/user/saveyy?xian=4&jd=' + lon + '&wd=' + lat);
                                writeForm.submit();
                            });
                        }
                    }
                    var convertor = new BMap.Convertor(); //这个类就是转换的对象
                    var pointArr = [];
                    pointArr.push(ggPoint);
                    convertor.translate(pointArr, 1, 5, translateCallback) //通过调用回调函数来进行转换。
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(latlon + "地址位置获取失败");
                }
            });
        };
    </script>
</head>
<body>
<div class="main">
    <c:forEach var="tea" items="${tealist}">
        <div class="shop1">
            <form class="writeForm" method="post">
                <div class="number">${tea.number}</div>
                <div class="name">${tea.name}</div>
                <div class="yourname">请输入您的姓名 <input type="text" name="name" size="4"></div>
                <div class="price">${tea.subject}</div>
                <div class="pricez">${tea.model}</div>
                <div class="find">
                    <a href="${pageContext.request.contextPath}/user/findyy?id=${tea.number}&flag=all">签到列表</a>
                </div>
                <c:if test="${tealist[0].subject=='2'||(tealist[0].subject=='3'&&tealist[0].model !='C1')}">
                    <div class="anniu">
                        <input type="hidden" name="number" value="${tea.number}">
                        <div class="one">
                            <input class="fourr" type="submit" value="签到">
                                <%--                            <a href=""></a>--%>
                        </div>
                    </div>
                </c:if>
                <c:if test="${tealist[0].subject=='3'&& tealist[0].model =='C1'}">
                    <div class="anniu">
                        <input type="hidden" name="number" value="${tea.number}">
                        <div class="one">
                            <input class="onee" type="button" value="1号线签到">
                            <input class="twoo" type="button" value="2号线签到">
                            <input class="threee" type="button" value="3号线签到">
                        </div>
                    </div>
                </c:if>
            </form>
        </div>
    </c:forEach>
</div>
</body>
</html>
